package com.xsd.rabbitmq.controller;

import com.xsd.rabbitmq.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 消息发送测试类
 * @Author: zhoufuzong
 * @Created: 2021-03-14 16:35:30
 * @Version: 1.1.0
 */

@RestController
public class SendMessageController {

    // 注入RabbitMq的模板类
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 测试
     * @return
     */
    @GetMapping("/sendmsg")
    public String sendMsg(@RequestParam String msg,@RequestParam String key){

        // 发送消息
        /*
        参数1： 交换机名称
        参数2: 路由key
        参数3：发送的消息
         */
        rabbitTemplate.convertAndSend(RabbitMQConfig.ITEM_TOPIC_EXCHANGE,key,msg);
        return "发送消息成功!";

    }
}
